--[[

	Minetest Ethereal Mod

	Created by ChinChow

	Updated by TenPlus1

]]

 -- DO NOT change settings below, use the settings.conf file instead

local function get_bool_setting(name, default)
	local value
	if minetest.settings then
		value = minetest.settings:get(name)
	elseif minetest.setting_get then
		value = minetest.setting_get(name)
	end

	if value == "true" then
		return true
	elseif value == "false" then
		return false
	else
		return default
	end
end

local function get_number_setting(name, default)
	local value
	if minetest.settings then
		value = minetest.settings:get(name)
	elseif minetest.setting_get then
		value = minetest.setting_get(name)
	end

	return tonumber(value) or default
end

ethereal = {

	version = "20220404",
	leaftype = get_number_setting('ethereal.leaftype') or 0,

	leafwalk = get_bool_setting('ethereal.leafwalk', false),
	cavedirt = get_bool_setting('ethereal.cavedirt', true),
	torchdrop = get_bool_setting('ethereal.torchdrop', true),
	papyruswalk = get_bool_setting('ethereal.papyruswalk', true),
	lilywalk = get_bool_setting('ethereal.lilywalk', true),
	xcraft = get_bool_setting('ethereal.xcraft', true),
	flight = get_bool_setting('ethereal.flight', true),

	glacier = get_number_setting('ethereal.glacier', 1),
	bamboo = get_number_setting('ethereal.bamboo', 1),
	mesa = get_number_setting('ethereal.mesa', 1),
	alpine = get_number_setting('ethereal.alpine', 1),
	healing = get_number_setting('ethereal.healing', 1),
	snowy = get_number_setting('ethereal.snowy', 1),
	frost = get_number_setting('ethereal.frost', 1),
	grassy = get_number_setting('ethereal.grassy', 1),
	caves = get_number_setting('ethereal.caves', 1),
	grayness = get_number_setting('ethereal.grayness', 1),
	grassytwo = get_number_setting('ethereal.grassytwo', 1),
	prairie = get_number_setting('ethereal.prairie', 1),
	jumble = get_number_setting('ethereal.jumble', 1),
	junglee = get_number_setting('ethereal.junglee', 1),
	desert = get_number_setting('ethereal.desert', 1),
	grove = get_number_setting('ethereal.grove', 1),
	mushroom = get_number_setting('ethereal.mushroom', 1),
	sandstone = get_number_setting('ethereal.sandstone', 1),
	quicksand = get_number_setting('ethereal.quicksand', 1),
	plains = get_number_setting('ethereal.plains', 1),
	savanna = get_number_setting('ethereal.savanna', 1),
	fiery = get_number_setting('ethereal.fiery', 1),
	sandclay = get_number_setting('ethereal.sandclay', 1),
	swamp = get_number_setting('ethereal.swamp', 1),
	sealife = get_number_setting('ethereal.sealife', 1),
	reefs = get_number_setting('ethereal.reefs', 1),
	sakura = get_number_setting('ethereal.sakura', 1),
	tundra = get_number_setting('ethereal.tundra', 1),
	mediterranean = get_number_setting('ethereal.mediterranean', 1)
}

local path = minetest.get_modpath("ethereal")

-- Load new settings if found
local input = io.open(path.."/settings.conf", "r")
if input then
	dofile(path .. "/settings.conf")
	input:close()
	input = nil
end

-- Intllib
local S
if minetest.get_translator then
	S = minetest.get_translator("ethereal")
elseif minetest.global_exists("intllib") then
	if intllib.make_gettext_pair then
		S = intllib.make_gettext_pair()
	else
		S = intllib.Getter()
	end
else
	S = function(s) return s end
end
ethereal.intllib = S

-- Falling node function
ethereal.check_falling = minetest.check_for_falling or nodeupdate

-- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function ethereal.check_creative(name)
	return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
end

dofile(path .. "/plantlife.lua")
dofile(path .. "/mushroom.lua")
dofile(path .. "/onion.lua")
dofile(path .. "/crystal.lua")
dofile(path .. "/water.lua")
dofile(path .. "/dirt.lua")
dofile(path .. "/food.lua")
dofile(path .. "/wood.lua")
dofile(path .. "/leaves.lua")
dofile(path .. "/sapling.lua")
dofile(path .. "/strawberry.lua")
dofile(path .. "/fishing.lua")
dofile(path .. "/extra.lua")
dofile(path .. "/sealife.lua")
dofile(path .. "/fences.lua")
dofile(path .. "/biomes.lua")
dofile(path .. "/ores.lua")
dofile(path .. "/schems.lua")
dofile(path .. "/decor.lua")
dofile(path .. "/compatibility.lua")
dofile(path .. "/stairs.lua")
dofile(path .. "/lucky_block.lua")

if ethereal.flight then
	dofile(path .. "/flight.lua")
end

-- Set bonemeal aliases
if minetest.get_modpath("bonemeal") then
	minetest.register_alias("ethereal:bone", "bonemeal:bone")
	minetest.register_alias("ethereal:bonemeal", "bonemeal:bonemeal")
else -- or return to where it came from
	minetest.register_alias("ethereal:bone", "default:dirt")
	minetest.register_alias("ethereal:bonemeal", "default:dirt")
end

if minetest.get_modpath("xanadu") then
	dofile(path .. "/plantpack.lua")
end

print ("[MOD] Ethereal loaded")
